
<script>
	$(function() {
		$(".delete").click(function(){
			var id=$(this).attr("href");
			//保存当前this
			var a=$(this);
			$.ajax({
				url:"delete.php",
				type:"GET",
				data:"id="+id,
				success:function(data){
					if(data)
						{
						//这里面的this已经不是上面点击的this，而是ajax返回的result，此处先用a保存this
						//下面删除的是父类兄弟节点的第一个
						//$($(a).parent().siblings()[0]).remove();
						//$(a).parent().next()[0].remove();  //不行,它们是dom,需要转换
						//$(a).parent().next().get(0).remove();  //不行,它们是dom,需要转换
						//下面删除的是父类后面紧邻的同辈元素第一个,【0】是转换为了dom，然后通过$转换为jquery操作
						//$($(a).parent().next()[0]).remove();
						//$($(a).parent().next().get(0)).remove();
						$(a).parent().next().first().remove();
						$(a).parent().remove();
						}
					else{
						}
					}
					});		
            return false;
			});
		$( "#accordion" ).accordion({
			autoHeight: false,
			navigation: true,
			active:false,
			collapsible:true,
			//event:'mouseover'
		});
	});
	</script>

<div class="demo">
	<div id="accordion">
<?php
//记录某组在accordion的顺序，从0开始
$count = - 1;
$result = mysql_query ( "select id,name,leader,status,comment from team" );
while ( $row = mysql_fetch_array ( $result ) ) {
	//记录顺序
	$count = $count + 1;
	//查询如果某组中有成员的状态为未知，则将组的状态改为未知
	$re = mysql_query ( "select * from member where groupId={$row['id']} and status='未知'" );
	if (mysql_num_rows ( $re )) {
		$img = "<font color='#fb940b'>未知&nbsp;</font><img src='images/unknow.jpg'/>";
	} else {
		if ($row ['status'] == "忙碌")
			$img = "<font color='#cc0001'>" . $row ['status'] . "</font><img src='images/high.jpg'/>";
		else if ($row ['status'] == "正常")
			$img = "<font color='#03cc02'>" . $row ['status'] . "</font><img src='images/normal.jpg'/>";
		else if ($row ['status'] == "yellow")
			$img = "<font color='#fb940b'>" . $row ['status'] . "</font><img src='images/low.jpg'/>";
		else
			$img = "<font color='#fb940b'>未知&nbsp;</font><img src='images/unknow.jpg'/>";
	}
	//组长的名字
	$name = $row ['leader'];
	//截取名称，对齐
	$leaderName = $row ['leader'];
	
	if (strlen ( $leaderName ) == 6) {
		$leaderName = $leaderName . "&nbsp;&nbsp;&nbsp;";
	}
	
	echo "<h3><font size='4'>{$row['name']}</font>" . "</br><img src='images/admin.png'/>:{$leaderName}&nbsp;&nbsp;<img src='images/status.png'/>:{$img}&nbsp;&nbsp;<img src='images/comment.png'/>:<span id='grounpComment'>{$row['comment']}</span></h3>";
	
	//下面是每个小组的详细信息
	echo "<div id='main" . $row ['id'] . "'>";
	$res = mysql_query ( "select * from member where groupId=" . $row ['id'] );
	
	while ( $r = mysql_fetch_array ( $res ) ) {
		//如果某个成员的名字是两位，则加几个空格，为了对齐
		$memberName = $r ['name'];
		if (strlen ( $memberName ) == 6) {
			$memberName = $memberName . "&nbsp;&nbsp;&nbsp;";
		}
		//
		$flagTime = $r ["time"];
		//只是客户端显示改变成员的状态和组的状态	
		$lastTime = $r ['lastUpdateTime'];
		date_default_timezone_set ( "PRC" );
		$nowTime = date ( "Y-m-d H:i:s" );
		$time = ( int ) ((strtotime ( $nowTime ) - strtotime ( $lastTime )) / (24 * 3600)) + 1;
		if ($time > $r ["time"]) {
			//更改成员时间状态
			$updatesql = "update member set status='未知' where id=" . $r ['id'];
			mysql_query ( $updatesql );
			$updatesql2 = "update team set status='未知' where id=" . $row ['id'];
			mysql_query ( $updatesql2 );
			$time = "*";
			$flagTime = "*";
		
		}
		echo "<span>";
		//如果是管理员登陆，添加编辑
		if (@$_SESSION ["name"] == $name) {
			echo "<a class='edit' rel='{$name}' href='{$r['id']}'><img src='images/user.png'/><span>{$memberName}</span>&nbsp;&nbsp;<img src='images/edit.png' alt='编辑成员' title='编辑成员'/></a>&nbsp;&nbsp;" . "<img src='images/status2.png'/>";
			//如果有管理员登录，记录该组的顺序
			@$_SESSION ["count"] = $count;
		} else {
			echo "<img src='images/user.png'/>{$memberName}&nbsp;&nbsp;&nbsp;&nbsp;<img src='images/status2.png'/>";
		}
		
		if ($r ['status'] == "忙碌")
			echo "<span><font color='#cc0001'>" . $r ['status'] . "&nbsp;</font><img src='images/high.jpg'/></span>";
		else if ($r ['status'] == "正常")
			echo "<span><font color='#03cc02'>" . $r ['status'] . "&nbsp;</font><img src='images/normal.jpg'/></span>";
		else if ($r ['status'] == "空闲")
			echo "<span><font color='#fb940b'>" . $r ['status'] . "&nbsp;</font><img src='images/low.jpg'/></span>";
		else
			echo "<span><font color='#fb940b'>未知&nbsp;</font><img src='images/unknow.jpg'/></span>";
		echo "&nbsp;&nbsp;<img src='images/day.png'/>&nbsp;<span><font color='red'>{$time}</font>/{$flagTime}天</span>&nbsp;&nbsp;";
		echo "<img src='images/task.png'/>&nbsp;<span>{$r["remark"]}</span>&nbsp;&nbsp;";
		if (@$_SESSION ["name"] == $name && $r ['name'] != $name) {
			echo "<a class='delete' href='{$r['id']}'><img src='images/delete.png' alt='删除成员' title='删除成员'/></a>";
		}
		echo "</span>";
		echo "<br/>";
	}
	//	echo "<br/>";
	if (@$_SESSION ["name"] == $name) {
		//把组ID通过session保存，方便dialog读取
		$_SESSION ["groupId"] = $row ['id'];
		echo "<a id='addMember' href='#'><img src='images/adduser.png' alt='新增成员' title='新增成员'/></a>";
		echo "&nbsp;&nbsp;&nbsp;<a rel='{$row['comment']}' href='{$row['id']}' id='editcomment'><img src='images/editcomment.png' alt='修改组备注' title='修改组备注'/></a>";
	}
	echo "</div>";

	//输出每个小组详细信息完毕
}
mysql_close ( $conn );

?>
</div>
</div>
<?php
//判断$_Session['count']，如果不等于空，
if (isset ( $_SESSION ['count'] )) {
	echo "<script Language = \"javascript\">";
	echo "$(function(){";
	echo "$('#accordion').accordion({ active:" . $_SESSION ['count'] . "});";
	echo "});";
	echo "</script>";
}
?>


